package com.example.tests;

import static org.testng.Assert.assertEquals;

import java.util.Collections;
import java.util.List;
import java.util.Random;

import org.testng.annotations.Test;

public class PersonRemovalTests extends TestBase {

	@Test
	public void deleteSomePerson() {
		app.getNavigationHelper().openMainPage();

		// save old state
		List<PersonData> oldList = app.getPersonHelper().getPersons();

		Random rnd = new Random();
		int index = rnd.nextInt(oldList.size() - 1);

		// actions
		app.getPersonHelper().initPersonModifications(1);
		app.getPersonHelper().deletePerson();
		app.getNavigationHelper().retutnToMainPage();

		// save new state
		List<PersonData> newList = app.getPersonHelper().getPersons();

		// compare
		oldList.remove(index);
		Collections.sort(oldList);
		assertEquals(newList, oldList);
	}
}
